Skip to content

feat: add authz dependency injections#1539

Draft
shree-iyengar-dls wants to merge 22 commits into
tiled-token-validationfrom
add_depedency_injection
Draft

feat: add authz dependency injections#1539
shree-iyengar-dls wants to merge 22 commits into
tiled-token-validationfrom
add_depedency_injection

Conversation

@shree-iyengar-dls
Copy link
Copy Markdown
Contributor

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 94.33962% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.75%. Comparing base (9865265) to head (2c84b6b).

Files with missing lines Patch % Lines
src/blueapi/service/main.py 78.57% 3 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           tiled-token-validation    #1539      +/-   ##
==========================================================
- Coverage                   95.79%   95.75%   -0.04%     
==========================================================
  Files                          44       44              
  Lines                        3280     3325      +45     
==========================================================
+ Hits                         3142     3184      +42     
- Misses                        138      141       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@shree-iyengar-dls shree-iyengar-dls marked this pull request as ready for review May 15, 2026 14:27
@shree-iyengar-dls shree-iyengar-dls requested a review from a team as a code owner May 15, 2026 14:27
Comment thread src/blueapi/service/main.py Outdated
@shree-iyengar-dls shree-iyengar-dls marked this pull request as draft May 18, 2026 15:13
@shree-iyengar-dls shree-iyengar-dls changed the title feat: add authz dependency injection feat: add authz dependency injections May 20, 2026
@tpoliaw tpoliaw force-pushed the add_depedency_injection branch from 27a9865 to ae58c78 Compare June 2, 2026 10:21
@tpoliaw tpoliaw changed the base branch from main to submit-task-auth June 2, 2026 10:55
@tpoliaw tpoliaw changed the base branch from submit-task-auth to tiled-token-validation June 2, 2026 11:12
@tpoliaw tpoliaw force-pushed the tiled-token-validation branch from b575c2b to b6049c8 Compare June 3, 2026 10:49
@tpoliaw tpoliaw force-pushed the add_depedency_injection branch from ae58c78 to 8112e4b Compare June 3, 2026 10:49
Copy link
Copy Markdown
Contributor

@ZohebShaikh ZohebShaikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good, few comments

Comment thread src/blueapi/service/authorization.py Outdated
from blueapi.service.model import TaskRequest

LOGGER = logging.getLogger(__name__)
INSTRUMENT_SESSION_RE = re.compile(r"^[a-z]{2}(?P<proposal>\d+)-(?P<visit>\d+)$")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we use the same value here ? Maybe move it to a constants file and import it from there

I had a look at the ISypB database they have all lower-case first 2 characters. So the above link regex should drop A-Z

We never make any check on the code(cm,sm..) of the visit, so why bother checking if it is 2 character and a-z

because it will pass even if you write cm12345-1 or ab12345-1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved it to the root of utils for now until there are enough constants to be worth a module.

I think it makes sense to keep the prefix check to ensure that 123-456 isn't accepted as a valid visit. We might be able to confirm the correct valid in future.

Comment thread src/blueapi/service/main.py Outdated
Comment thread src/blueapi/config.py
Comment thread src/blueapi/service/main.py Outdated
Comment thread tests/unit_tests/service/test_authorization.py Outdated
@tpoliaw tpoliaw force-pushed the tiled-token-validation branch from b6049c8 to 63009c0 Compare June 5, 2026 14:27
@tpoliaw tpoliaw force-pushed the add_depedency_injection branch from 8112e4b to a4c6778 Compare June 5, 2026 14:28
@tpoliaw tpoliaw force-pushed the tiled-token-validation branch from 63009c0 to 9865265 Compare June 5, 2026 16:01
@tpoliaw tpoliaw force-pushed the add_depedency_injection branch from a4c6778 to 4fa20de Compare June 5, 2026 16:01
):
task = runner.run(interface.get_task_by_id, task_id)

if opa and not opa.admin() and (task and fedid != task.task.metadata.get("user")):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only checks task access if OPA is configured. Do we want to restrict access based on user name when authn is enabled but authz is not?

Comment thread src/blueapi/service/authorization.py Outdated
from blueapi.service.model import TaskRequest

LOGGER = logging.getLogger(__name__)
INSTRUMENT_SESSION_RE = re.compile(r"^[a-z]{2}(?P<proposal>\d+)-(?P<visit>\d+)$")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved it to the root of utils for now until there are enough constants to be worth a module.

I think it makes sense to keep the prefix check to ensure that 123-456 isn't accepted as a valid visit. We might be able to confirm the correct valid in future.

Comment thread src/blueapi/service/main.py Outdated
Comment thread src/blueapi/config.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants